package org.tcx.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.tcx.common.LogUtil;

public class EncodingFilter implements Filter {
	private static Log log = LogFactory.getLog(EncodingFilter.class);

	public void destroy() {
		log.debug("enter");
		// TODO Auto-generated method stub
		log.debug("leave");
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		log.debug("enter"
				+ LogUtil.arg("request, response, chain", request, response,
						chain));
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		chain.doFilter(request, response);
		log.debug("leave");
	}

	public void init(FilterConfig filterConfig) throws ServletException {
		log.debug("enter" + LogUtil.arg("filterConfig", filterConfig));
		// TODO Auto-generated method stub
		log.debug("leave");
	}
}
